package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;

public class COUNT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    int i = 0;
    for (int j = 0; j < paramArrayOfObject.length; ++j)
    {
      if (paramArrayOfObject[j] == null)
        break label29:
      i += parseObjectCount(paramArrayOfObject[j]);
    }
    label29: return new Integer(i);
  }

  private int parseObjectCount(Object paramObject)
  {
    if (paramObject instanceof FArray)
      return ((FArray)paramObject).length();
    if (paramObject != Primitive.NULL)
      return 1;
    return 0;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "COUNT(value1,value2,…): 计算数组或数据区域中所含项的个数。\nValue1,value2,…:可包含任何类型数据的参数。";
  }

  public String getEN()
  {
    return "COUNT(value1,value2,…): Counts the number of cells that contain numbers and also numbers within the list of arguments.\nValue1, value2, ...  are 1 to 30 arguments that can contain or refer to a variety of different types of data, but only numbers are counted.\n\nRemarks:\n1. Arguments that are numbers, dates, or text representations of numbers are counted; arguments that are error values or text that cannot be translated into numbers are ignored. \n2. If an argument is an array or reference, only numbers in that array or reference are counted. Empty cells, logical values, text, or error values in the array or reference are ignored. If you need to count logical values, text, or error values, use the COUNTA function. ";
  }
}